#include "exception.h"
#include "thread.h"
#include <errno.h>
namespace CThread
{

Thread::Thread(Runnable* pRunnable) :
	m_tid(0),
	m_pRunnable(pRunnable)
{
}

Thread::~Thread()
{
	join();
}

void Thread::start()
{
	int iRet;
	if ( (iRet=pthread_create(&m_tid, NULL, threadMain, (void*)this)) != 0 )
	{
		throw SystemResourceException(string("pthread_create: ")+strerror(iRet));
	}
}

void Thread::join()
{
	pthread_join(m_tid, NULL) == 0;
}

void* Thread::threadMain(void* arg)
{
	Thread* pThread = (Thread*)arg;
	pThread->run();
	return (void*)0;
}

};
